public class HeapSort {
    //利用建堆和堆的删除的思想实现堆排序
    public static int[] heapSort(int[] array) {
         Heap heap = new Heap();
         heap.createHeap(array);
         //记录下数组的起始有效长度
         int length = heap.usedSize;

         //利用堆的删除方法，进行排序
        for (int i = 0; i < length; i++) {
            int last = heap.usedSize - 1;
            heap.swap(0,last);
            heap.usedSize--;

           heap.siftDown(0,heap.usedSize);
        }

         heap.usedSize = length;
         return heap.heap;
    }
}
